﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace uam_fps_game.NetComponents
{
    public class ServerPlayerNetComp : NetComp
    {
        /// Server in one message can receive from client many PlayerInput objects, corresponding to user input states during many frames.
        /// This is the data that server uses to run simulation.
        /// Objects on the queue correspond to state of user input in particular frames.
        public Queue<PlayerInput> LastReceivedInputs { get; private set; }

        /// Here, most recent PlayerState is set by node using the component.
        /// This is the effect of server simulation, and will be sent to clients.
        public PlayerState NewStateToSend { get; set; }

        public ServerPlayerNetComp()
        {
            LastReceivedInputs = new Queue<PlayerInput>();
            NewStateToSend = null;
        }

        internal override void Update(float deltaTime)
        {
            if (NewStateToSend != null) // (Given that on server both game simulation update and network update should run at the same rate, this check would not be neccessary, since there'd always be new data to send
            {
                // send state to clients - PLAYER_STATE message

                NewStateToSend = null;
            }
        }

        internal override void ProcessMessage()
        {
            // receive PLAYER_INPUT message
            // PSEUDOCODE: foreach (PLAYER_INPUT message) LastInputs.Add(input)
        }
    }
}
